package com.imc.platform.frame.service;

import com.imc.platform.frame.mapper.ICountMapper;
import com.imc.platform.frame.repository.VisitSummaryRepository;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by tanweiping on 2018/9/17.
 */
@Transactional
@Service
public class CountService {

    @Autowired
    ICountMapper iCountMapper;

    @Autowired
    VisitSummaryRepository visitSummaryRepository;

    @Data@Builder
    public static class Summary{
        private String registerCount;
        //private String onlineCount;
        private String accessCount;
    }

    public Summary getSummary(HttpServletRequest request){
        Summary summary = Summary.builder().build();
        summary.setAccessCount(String.valueOf(visitSummaryRepository.count()));
        //summary.setOnlineCount(String.valueOf(request.getSession().getServletContext().getAttribute("onlineCount")));
        summary.setRegisterCount(String.valueOf(iCountMapper.getSummaryUserSize()));
        return summary;
    }

    public void UpdateAccessCount(){
        iCountMapper.UpdateAccessCount();
    }
}
